home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / fileutil.zip / SYSTEM.H < prev    next >
C/C++ Source or Header  |  1992-02-22  |  5KB  |  227 lines

  1. /* system-dependent definitions for fileutils programs.
  2.    Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 1, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Include sys/types.h before this file.  */
  19.  
  20. /* MS-DOS port (c) 1990 by Thorsten Ohl, ohl@gnu.ai.mit.edu
  21.    This port is also distributed under the terms of the
  22.    GNU General Public License as published by the
  23.    Free Software Foundation.
  24.  
  25.    Please note that this file is not identical to the
  26.    original GNU release, you should have received this
  27.    code as patch to the official release.
  28.  
  29.    $Header: e:/gnu/fileutil/RCS/system.h 1.4.0.2 90/09/19 12:27:45 tho Exp $
  30.  */
  31.  
  32. #include <sys/stat.h>
  33.  
  34. #ifdef _POSIX_SOURCE
  35. #include <unistd.h>
  36. #include <limits.h>
  37. #else
  38.  
  39. #ifdef USG
  40. #ifdef MSDOS
  41. #include <time.h>
  42. #else /* not MSDOS */
  43. #include <sys/times.h>
  44. #endif /* not MSDOS */
  45. #else
  46. #include <sys/time.h>
  47. #endif
  48.  
  49. #ifndef MSDOS
  50. #include <sys/param.h>
  51. #endif /* not MSDOS */
  52. #define _POSIX_PATH_MAX 255
  53. #define _POSIX_NAME_MAX 14
  54.  
  55. #ifndef PATH_MAX
  56. #ifdef MAXPATHLEN
  57. #define PATH_MAX MAXPATHLEN
  58. #else
  59. #define PATH_MAX _POSIX_PATH_MAX
  60. #endif
  61. #endif
  62.  
  63. #ifndef NAME_MAX
  64. #ifdef MAXNAMLEN
  65. #define NAME_MAX MAXNAMLEN
  66. #else
  67. #define NAME_MAX _POSIX_NAME_MAX
  68. #endif
  69. #endif
  70.  
  71. #endif
  72.  
  73. /* Filesystem device blocksize. */
  74. #ifndef DEV_BSIZE
  75. #ifdef BSIZE
  76. #define DEV_BSIZE BSIZE
  77. #else
  78. #define DEV_BSIZE 512
  79. #endif
  80. #endif
  81.  
  82. #ifdef _POSIX_SOURCE
  83. #define major(dev)  (((dev) >> 8) & 0xff)
  84. #define minor(dev)  ((dev) & 0xff)
  85. #define makedev(maj, min)  (((maj) << 8) | (min))
  86. #else
  87. #ifdef USG
  88. #ifdef MSDOS
  89. #define major(dev)  (((dev) >> 8) & 0xff)
  90. #define minor(dev)  ((dev) & 0xff)
  91. #else /* not MSDOS */
  92. #include <sys/sysmacros.h>
  93. #endif /* not MSDOS */
  94. #endif
  95. #endif
  96.  
  97. #ifdef _POSIX_SOURCE
  98. #include <utime.h>
  99. #else
  100. struct utimbuf
  101. {
  102.   long actime;
  103.   long modtime;
  104. };
  105. #ifdef MSDOS
  106. int utime(char *, struct utimbuf *);
  107. #endif /* MSDOS */
  108. #endif
  109.  
  110. #if defined(USG) || defined(STDC_HEADERS)
  111. #include <string.h>
  112. #define index strchr
  113. #define rindex strrchr
  114. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  115. #define bzero(s, n) memset ((s), 0, (n))
  116. #endif
  117.  
  118. #if defined(USG) || defined(_POSIX_SOURCE)
  119. #ifndef _POSIX_SOURCE
  120. /* Args for access. */
  121. #define F_OK 0
  122. #define X_OK 1
  123. #define W_OK 2
  124. #define R_OK 4
  125.  
  126. char *getcwd ();
  127. #endif
  128. #define getwd(buf) getcwd ((buf), PATH_MAX + 2)
  129.  
  130. /* Args for lseek. */
  131. #define L_SET 0
  132. #define L_INCR 1
  133. #define L_XTND 2
  134. #else
  135. #include <strings.h>
  136. #include <sys/file.h>
  137.  
  138. char *getwd ();
  139. #endif
  140.  
  141. #include <fcntl.h>
  142.  
  143. #ifdef DIRENT
  144. #include <dirent.h>
  145. #ifdef direct
  146. #undef direct
  147. #endif
  148. #define direct dirent
  149. #define NLENGTH(direct) (strlen((direct)->d_name))
  150. #else
  151. #define NLENGTH(direct) ((direct)->d_namlen)
  152. #ifdef USG
  153. #ifdef SYSNDIR
  154. #include <sys/ndir.h>
  155. #else
  156. #include <ndir.h>
  157. #endif
  158. #else /* must be BSD */
  159. #include <sys/dir.h>
  160. #endif
  161. #endif
  162.  
  163.  
  164. #ifdef MSDOS
  165.  
  166. #define ST_BLKSIZE(statbuf) BLKSIZE
  167. #define ST_NBLOCKS(statbuf) (((statbuf).st_size + DEV_BSIZE - 1) / DEV_BSIZE)
  168.  
  169. #else /* not MSDOS */
  170.  
  171. /* Extract data from a `struct stat'.
  172.    ST_BLKSIZE: Optimal I/O blocksize for the file.
  173.    ST_NBLOCKS: Number of blocks in the file (including indirect blocks). */
  174. #ifdef _POSIX_SOURCE
  175. #define ST_BLKSIZE(statbuf) DEV_BSIZE
  176. #define ST_NBLOCKS(statbuf) (((statbuf).st_size + DEV_BSIZE - 1) / DEV_BSIZE)
  177. #else
  178. #ifdef STBLOCKS_MISSING
  179. #define ST_BLKSIZE(statbuf) DEV_BSIZE
  180. #define ST_NBLOCKS(statbuf) (st_blocks ((statbuf).st_size))
  181. #else
  182. /* Some systems, like Sequents, return st_blksize of 0 on pipes. */
  183. #define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
  184.                  ? (statbuf).st_blksize : DEV_BSIZE)
  185. #define ST_NBLOCKS(statbuf) ((statbuf).st_blocks)
  186. #endif
  187. #endif
  188.  
  189. #endif /* not MSDOS */
  190.  
  191. /* Convert B blocks of DEV_BSIZE bytes
  192.    to kilobytes if K is nonzero, otherwise to blocks of 512 bytes. */
  193.  
  194. #if DEV_BSIZE == 512
  195. #define convert_blocks(b, k) ((k) ? ((b) + 1) / 2 : (b))
  196. #else
  197. #if DEV_BSIZE == 1024
  198. #define convert_blocks(b, k) ((k) ? (b) : (b) * 2)
  199. #else
  200. #define convert_blocks(b, k) ((k) \
  201.                   ? ((b) * DEV_BSIZE + 1023) / 1024 \
  202.                   : ((b) * DEV_BSIZE + 511) / 512)
  203. #endif
  204. #endif
  205.  
  206. #ifndef S_IFLNK
  207. #define lstat stat
  208. #endif
  209.  
  210. #ifndef SIGTYPE
  211. #define SIGTYPE void
  212. #endif
  213.  
  214. #ifdef __GNUC__
  215. #define alloca __builtin_alloca
  216. #else
  217. #ifdef sparc
  218. #include <alloca.h>
  219. #else
  220. #ifdef MSDOS
  221. #include <malloc.h>
  222. #else
  223. char *alloca ();
  224. #endif
  225. #endif
  226. #endif
  227.